<!DOCTYPE html>
<html>
<head lang="zh-cmn-Hans">
    <meta charset="UTF-8">
    <title>Fly.js Demo</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=0.5,user-scalable=no"/>
    <!--[if lt IE 9]>
    <script src="//cdn.bootcss.com/es5-shim/4.5.9/es5-shim.min.js"></script>
    <script src="//cdn.bootcss.com/es5-shim/4.5.9/es5-sham.min.js"></script>
    <script src="//cdn.bootcss.com/json3/3.3.2/json3.min.js"></script>
    <![endif]-->
    <!--[if lt IE 10]>
    <script src="//cdn.bootcss.com/jquery-placeholder/2.3.1/jquery.placeholder.min.js"></script>
    <![endif]-->
    <!--<script src="https://cdn.bootcss.com/axios/0.16.2/axios.js"></script>-->
    <script src="../dist/fly.js"></script>

</head>
<style>
    html {
        font-size: 20px;
        -webkit-user-select: none;
    }
</style>
<body>
<div style="background: teal; font-size: 38px; color: #ffef68; text-shadow: 2px 2px 5px #ffef68; width: 400px; height: 400px; text-align: center">
    <div style="padding-top: 100px"> Fly.js</div>
</div>
open console panel to view log.
<script>
    //定义公共headers
    fly.config.headers = {xx: 5, bb: 6, dd: 7}

    //设置
    fly.config.params = {"token": "testtoken"};

    fly.interceptors.request.use(function (request) {
        //可以通过promise.reject／resolve直接中止请求
        console.log("interceptors.request", request)
        request.headers["X-Tag"] = "fly.js";
        //return Promise.resolve("xx")
        return request;
    })

    fly.interceptors.response.use(
        function (response) {
            console.log("interceptors.response", response)
            return Promise.resolve(response.data)
        },
        function (err) {
            console.log("error-interceptor", err)
        }
    )

    fly.get("https://www.baidu.com", {aa: 8, bb: 9, tt: {xx: 5}})
        .then(function (d) {
            console.log("cross:", d)
        }).catch(function (e) {
        console.log("error", e)
    })

    fly.get("../package.json", {
        "a": "你好",
        "b": [5, "6"],
        "c": {"d": 8, "e": {"a": 5, "b": [66, 8]}}
    })
        .then(function (d) {
            console.log("get result:", d)
        }).catch(function (e) {
        console.log("error", e)
    })

    fly.get("../package.json?fm=true", {aa: 8, bb: 9, tt: {xx: 5}}, {
        headers: {
            "content-type": "application/x-www-form-urlencoded"
        }
    })
        .then(function (d) {
            console.log("post result:", d)
        }).catch(function (e) {
        console.log("error", e)
    })

    fly.post("../package.json", "xx=8")
        .then(function (d) {
            console.log("post result:", d)
        }).catch(function (e) {
        console.log("error", e)
    })

    fly.get("../package.json", "xxx=5", {
            params: {
                c: 1
            }
        }
    )

    fly.request("../aa/package.json", {hh: 5}, {method: "post"})
        .then(function (d) {
            console.log("ajax result:", d)
        }).catch(function (e) {
        console.log("error", e)
    })
</script>
</body>
</html>
